/*      */ package com.jcraft.jzlib;
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ public final class Deflate
/*      */ {
/*      */   private static final int MAX_MEM_LEVEL = 9;
/*      */   
/*      */ 
/*      */ 
/*      */   private static final int Z_DEFAULT_COMPRESSION = -1;
/*      */   
/*      */ 
/*      */ 
/*      */   private static final int MAX_WBITS = 15;
/*      */   
/*      */ 
/*      */ 
/*      */   private static final int DEF_MEM_LEVEL = 8;
/*      */   
/*      */ 
/*      */ 
/*      */   private static final int STORED = 0;
/*      */   
/*      */ 
/*      */ 
/*      */   private static final int FAST = 1;
/*      */   
/*      */ 
/*      */   private static final int SLOW = 2;
/*      */   
/*      */ 
/*      */ 
/*      */   static class Config
/*      */   {
/*      */     int good_length;
/*      */     
/*      */ 
/*      */     int max_lazy;
/*      */     
/*      */ 
/*      */     int nice_length;
/*      */     
/*      */ 
/*      */     int max_chain;
/*      */     
/*      */ 
/*      */     int func;
/*      */     
/*      */ 
/*      */ 
/*      */     Config(int good_length, int max_lazy, int nice_length, int max_chain, int func)
/*      */     {
/*   55 */       this.good_length = good_length;
/*   56 */       this.max_lazy = max_lazy;
/*   57 */       this.nice_length = nice_length;
/*   58 */       this.max_chain = max_chain;
/*   59 */       this.func = func;
/*      */     }
/*      */   }
/*      */   
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*   68 */   private static final Config[] config_table = new Config[10];
/*      */   
/*   70 */   static { config_table[0] = new Config(0, 0, 0, 0, 0);
/*   71 */     config_table[1] = new Config(4, 4, 8, 4, 1);
/*   72 */     config_table[2] = new Config(4, 5, 16, 8, 1);
/*   73 */     config_table[3] = new Config(4, 6, 32, 32, 1);
/*      */     
/*   75 */     config_table[4] = new Config(4, 4, 16, 16, 2);
/*   76 */     config_table[5] = new Config(8, 16, 32, 32, 2);
/*   77 */     config_table[6] = new Config(8, 16, 128, 128, 2);
/*   78 */     config_table[7] = new Config(8, 32, 128, 256, 2);
/*   79 */     config_table[8] = new Config(32, 128, 258, 1024, 2);
/*   80 */     config_table[9] = new Config(32, 258, 258, 4096, 2);
/*      */   }
/*      */   
/*   83 */   private static final String[] z_errmsg = { "need dictionary", 
/*      */   
/*   85 */     "stream end", 
/*   86 */     "", 
/*   87 */     "file error", 
/*   88 */     "stream error", 
/*   89 */     "data error", 
/*   90 */     "insufficient memory", 
/*   91 */     "buffer error", 
/*   92 */     "incompatible version", 
/*   93 */     "" };
/*      */   
/*      */   private static final int NeedMore = 0;
/*      */   
/*      */   private static final int BlockDone = 1;
/*      */   
/*      */   private static final int FinishStarted = 2;
/*      */   
/*      */   private static final int FinishDone = 3;
/*      */   
/*      */   private static final int PRESET_DICT = 32;
/*      */   
/*      */   private static final int Z_FILTERED = 1;
/*      */   
/*      */   private static final int Z_HUFFMAN_ONLY = 2;
/*      */   
/*      */   private static final int Z_DEFAULT_STRATEGY = 0;
/*      */   
/*      */   private static final int Z_NO_FLUSH = 0;
/*      */   
/*      */   private static final int Z_PARTIAL_FLUSH = 1;
/*      */   
/*      */   private static final int Z_SYNC_FLUSH = 2;
/*      */   
/*      */   private static final int Z_FULL_FLUSH = 3;
/*      */   
/*      */   private static final int Z_FINISH = 4;
/*      */   
/*      */   private static final int Z_OK = 0;
/*      */   
/*      */   private static final int Z_STREAM_END = 1;
/*      */   
/*      */   private static final int Z_NEED_DICT = 2;
/*      */   
/*      */   private static final int Z_ERRNO = -1;
/*      */   
/*      */   private static final int Z_STREAM_ERROR = -2;
/*      */   
/*      */   private static final int Z_DATA_ERROR = -3;
/*      */   
/*      */   private static final int Z_MEM_ERROR = -4;
/*      */   
/*      */   private static final int Z_BUF_ERROR = -5;
/*      */   
/*      */   private static final int Z_VERSION_ERROR = -6;
/*      */   
/*      */   private static final int INIT_STATE = 42;
/*      */   
/*      */   private static final int BUSY_STATE = 113;
/*      */   
/*      */   private static final int FINISH_STATE = 666;
/*      */   
/*      */   private static final int Z_DEFLATED = 8;
/*      */   
/*      */   private static final int STORED_BLOCK = 0;
/*      */   
/*      */   private static final int STATIC_TREES = 1;
/*      */   
/*      */   private static final int DYN_TREES = 2;
/*      */   
/*      */   private static final int Z_BINARY = 0;
/*      */   
/*      */   private static final int Z_ASCII = 1;
/*      */   
/*      */   private static final int Z_UNKNOWN = 2;
/*      */   
/*      */   private static final int Buf_size = 16;
/*      */   
/*      */   private static final int REP_3_6 = 16;
/*      */   
/*      */   private static final int REPZ_3_10 = 17;
/*      */   
/*      */   private static final int REPZ_11_138 = 18;
/*      */   
/*      */   private static final int MIN_MATCH = 3;
/*      */   
/*      */   private static final int MAX_MATCH = 258;
/*      */   
/*      */   private static final int MIN_LOOKAHEAD = 262;
/*      */   
/*      */   private static final int MAX_BITS = 15;
/*      */   
/*      */   private static final int D_CODES = 30;
/*      */   
/*      */   private static final int BL_CODES = 19;
/*      */   
/*      */   private static final int LENGTH_CODES = 29;
/*      */   
/*      */   private static final int LITERALS = 256;
/*      */   
/*      */   private static final int L_CODES = 286;
/*      */   
/*      */   private static final int HEAP_SIZE = 573;
/*      */   
/*      */   private static final int END_BLOCK = 256;
/*      */   
/*      */   ZStream strm;
/*      */   
/*      */   int status;
/*      */   
/*      */   byte[] pending_buf;
/*      */   
/*      */   int pending_buf_size;
/*      */   
/*      */   int pending_out;
/*      */   
/*      */   int pending;
/*      */   
/*      */   int noheader;
/*      */   
/*      */   byte data_type;
/*      */   
/*      */   byte method;
/*      */   
/*      */   int last_flush;
/*      */   
/*      */   int w_size;
/*      */   
/*      */   int w_bits;
/*      */   
/*      */   int w_mask;
/*      */   
/*      */   byte[] window;
/*      */   
/*      */   int window_size;
/*      */   
/*      */   short[] prev;
/*      */   
/*      */   short[] head;
/*      */   
/*      */   int ins_h;
/*      */   
/*      */   int hash_size;
/*      */   
/*      */   int hash_bits;
/*      */   
/*      */   int hash_mask;
/*      */   
/*      */   int hash_shift;
/*      */   
/*      */   int block_start;
/*      */   
/*      */   int match_length;
/*      */   
/*      */   int prev_match;
/*      */   
/*      */   int match_available;
/*      */   
/*      */   int strstart;
/*      */   
/*      */   int match_start;
/*      */   
/*      */   int lookahead;
/*      */   
/*      */   int prev_length;
/*      */   
/*      */   int max_chain_length;
/*      */   
/*      */   int max_lazy_match;
/*      */   int level;
/*      */   int strategy;
/*      */   int good_match;
/*      */   int nice_match;
/*      */   short[] dyn_ltree;
/*      */   short[] dyn_dtree;
/*      */   short[] bl_tree;
/*  259 */   Tree l_desc = new Tree();
/*  260 */   Tree d_desc = new Tree();
/*  261 */   Tree bl_desc = new Tree();
/*      */   
/*      */ 
/*  264 */   short[] bl_count = new short[16];
/*      */   
/*      */ 
/*  267 */   int[] heap = new int['Ƚ'];
/*      */   
/*      */ 
/*      */   int heap_len;
/*      */   
/*      */ 
/*      */   int heap_max;
/*      */   
/*  275 */   byte[] depth = new byte['Ƚ'];
/*      */   
/*      */ 
/*      */ 
/*      */   int l_buf;
/*      */   
/*      */ 
/*      */ 
/*      */   int lit_bufsize;
/*      */   
/*      */ 
/*      */ 
/*      */   int last_lit;
/*      */   
/*      */ 
/*      */ 
/*      */   int d_buf;
/*      */   
/*      */ 
/*      */ 
/*      */   int opt_len;
/*      */   
/*      */ 
/*      */ 
/*      */   int static_len;
/*      */   
/*      */ 
/*      */ 
/*      */   int matches;
/*      */   
/*      */ 
/*      */ 
/*      */   int last_eob_len;
/*      */   
/*      */ 
/*      */ 
/*      */   short bi_buf;
/*      */   
/*      */ 
/*      */   int bi_valid;
/*      */   
/*      */ 
/*      */ 
/*      */   Deflate()
/*      */   {
/*  320 */     this.dyn_ltree = new short['Ѻ'];
/*  321 */     this.dyn_dtree = new short[122];
/*  322 */     this.bl_tree = new short[78];
/*      */   }
/*      */   
/*      */   void lm_init()
/*      */   {
/*  327 */     this.window_size = (2 * this.w_size);
/*      */     
/*  329 */     this.head[(this.hash_size - 1)] = 0;
/*  330 */     for (int i = 0; i < this.hash_size - 1; i++) {
/*  331 */       this.head[i] = 0;
/*      */     }
/*      */     
/*      */ 
/*  335 */     this.max_lazy_match = config_table[this.level].max_lazy;
/*  336 */     this.good_match = config_table[this.level].good_length;
/*  337 */     this.nice_match = config_table[this.level].nice_length;
/*  338 */     this.max_chain_length = config_table[this.level].max_chain;
/*      */     
/*  340 */     this.strstart = 0;
/*  341 */     this.block_start = 0;
/*  342 */     this.lookahead = 0;
/*  343 */     this.match_length = (this.prev_length = 2);
/*  344 */     this.match_available = 0;
/*  345 */     this.ins_h = 0;
/*      */   }
/*      */   
/*      */ 
/*      */   void tr_init()
/*      */   {
/*  351 */     this.l_desc.dyn_tree = this.dyn_ltree;
/*  352 */     this.l_desc.stat_desc = StaticTree.static_l_desc;
/*      */     
/*  354 */     this.d_desc.dyn_tree = this.dyn_dtree;
/*  355 */     this.d_desc.stat_desc = StaticTree.static_d_desc;
/*      */     
/*  357 */     this.bl_desc.dyn_tree = this.bl_tree;
/*  358 */     this.bl_desc.stat_desc = StaticTree.static_bl_desc;
/*      */     
/*  360 */     this.bi_buf = 0;
/*  361 */     this.bi_valid = 0;
/*  362 */     this.last_eob_len = 8;
/*      */     
/*      */ 
/*  365 */     init_block();
/*      */   }
/*      */   
/*      */   void init_block()
/*      */   {
/*  370 */     for (int i = 0; i < 286; i++)
/*  371 */       this.dyn_ltree[(i * 2)] = 0;
/*  372 */     for (int i = 0; i < 30; i++)
/*  373 */       this.dyn_dtree[(i * 2)] = 0;
/*  374 */     for (int i = 0; i < 19; i++) {
/*  375 */       this.bl_tree[(i * 2)] = 0;
/*      */     }
/*  377 */     this.dyn_ltree['Ȁ'] = 1;
/*  378 */     this.opt_len = (this.static_len = 0);
/*  379 */     this.last_lit = (this.matches = 0);
/*      */   }
/*      */   
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */   void pqdownheap(short[] tree, int k)
/*      */   {
/*  390 */     int v = this.heap[k];
/*  391 */     int j = k << 1;
/*  392 */     while (j <= this.heap_len)
/*      */     {
/*  394 */       if ((j < this.heap_len) && (smaller(tree, this.heap[(j + 1)], this.heap[j], this.depth))) {
/*  395 */         j++;
/*      */       }
/*      */       
/*  398 */       if (smaller(tree, v, this.heap[j], this.depth)) {
/*      */         break;
/*      */       }
/*      */       
/*  402 */       this.heap[k] = this.heap[j];
/*  403 */       k = j;
/*      */       
/*  405 */       j <<= 1;
/*      */     }
/*  407 */     this.heap[k] = v;
/*      */   }
/*      */   
/*      */   static boolean smaller(short[] tree, int n, int m, byte[] depth) {
/*  411 */     short tn2 = tree[(n * 2)];
/*  412 */     short tm2 = tree[(m * 2)];
/*  413 */     return (tn2 < tm2) || ((tn2 == tm2) && (depth[n] <= depth[m]));
/*      */   }
/*      */   
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */   void scan_tree(short[] tree, int max_code)
/*      */   {
/*  422 */     int prevlen = -1;
/*      */     
/*  424 */     int nextlen = tree[1];
/*  425 */     int count = 0;
/*  426 */     int max_count = 7;
/*  427 */     int min_count = 4;
/*      */     
/*  429 */     if (nextlen == 0) {
/*  430 */       max_count = 138;
/*  431 */       min_count = 3;
/*      */     }
/*  433 */     tree[((max_code + 1) * 2 + 1)] = -1;
/*      */     
/*  435 */     for (int n = 0; n <= max_code; n++) {
/*  436 */       int curlen = nextlen;
/*  437 */       nextlen = tree[((n + 1) * 2 + 1)];
/*  438 */       count++; if ((count >= max_count) || (curlen != nextlen))
/*      */       {
/*  440 */         if (count < min_count) {
/*  441 */           int tmp96_95 = (curlen * 2); short[] tmp96_89 = this.bl_tree;tmp96_89[tmp96_95] = ((short)(tmp96_89[tmp96_95] + count));
/*  442 */         } else if (curlen != 0) {
/*  443 */           if (curlen != prevlen) {
/*  444 */             int tmp126_125 = (curlen * 2); short[] tmp126_119 = this.bl_tree;tmp126_119[tmp126_125] = ((short)(tmp126_119[tmp126_125] + 1)); }
/*  445 */           short[] tmp138_133 = this.bl_tree;tmp138_133[32] = ((short)(tmp138_133[32] + 1));
/*  446 */         } else if (count <= 10) {
/*  447 */           short[] tmp160_155 = this.bl_tree;tmp160_155[34] = ((short)(tmp160_155[34] + 1));
/*      */         } else {
/*  449 */           short[] tmp175_170 = this.bl_tree;tmp175_170[36] = ((short)(tmp175_170[36] + 1));
/*      */         }
/*  451 */         count = 0;
/*  452 */         prevlen = curlen;
/*  453 */         if (nextlen == 0) {
/*  454 */           max_count = 138;
/*  455 */           min_count = 3;
/*  456 */         } else if (curlen == nextlen) {
/*  457 */           max_count = 6;
/*  458 */           min_count = 3;
/*      */         } else {
/*  460 */           max_count = 7;
/*  461 */           min_count = 4;
/*      */         }
/*      */       }
/*      */     }
/*      */   }
/*      */   
/*      */ 
/*      */ 
/*      */ 
/*      */   int build_bl_tree()
/*      */   {
/*  472 */     scan_tree(this.dyn_ltree, this.l_desc.max_code);
/*  473 */     scan_tree(this.dyn_dtree, this.d_desc.max_code);
/*      */     
/*      */ 
/*  476 */     this.bl_desc.build_tree(this);
/*      */     
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*  484 */     for (int max_blindex = 18; max_blindex >= 3; max_blindex--) {
/*  485 */       if (this.bl_tree[(Tree.bl_order[max_blindex] * 2 + 1)] != 0) {
/*      */         break;
/*      */       }
/*      */     }
/*  489 */     this.opt_len += 3 * (max_blindex + 1) + 5 + 5 + 4;
/*      */     
/*  491 */     return max_blindex;
/*      */   }
/*      */   
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */   void send_all_trees(int lcodes, int dcodes, int blcodes)
/*      */   {
/*  500 */     send_bits(lcodes - 257, 5);
/*  501 */     send_bits(dcodes - 1, 5);
/*  502 */     send_bits(blcodes - 4, 4);
/*  503 */     for (int rank = 0; rank < blcodes; rank++) {
/*  504 */       send_bits(this.bl_tree[(Tree.bl_order[rank] * 2 + 1)], 3);
/*      */     }
/*  506 */     send_tree(this.dyn_ltree, lcodes - 1);
/*  507 */     send_tree(this.dyn_dtree, dcodes - 1);
/*      */   }
/*      */   
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */   void send_tree(short[] tree, int max_code)
/*      */   {
/*  516 */     int prevlen = -1;
/*      */     
/*  518 */     int nextlen = tree[1];
/*  519 */     int count = 0;
/*  520 */     int max_count = 7;
/*  521 */     int min_count = 4;
/*      */     
/*  523 */     if (nextlen == 0) {
/*  524 */       max_count = 138;
/*  525 */       min_count = 3;
/*      */     }
/*      */     
/*  528 */     for (int n = 0; n <= max_code; n++) {
/*  529 */       int curlen = nextlen;
/*  530 */       nextlen = tree[((n + 1) * 2 + 1)];
/*  531 */       count++; if ((count >= max_count) || (curlen != nextlen))
/*      */       {
/*  533 */         if (count < min_count) {
/*      */           do {
/*  535 */             send_code(curlen, this.bl_tree);
/*  536 */             count--; } while (count != 0);
/*  537 */         } else if (curlen != 0) {
/*  538 */           if (curlen != prevlen) {
/*  539 */             send_code(curlen, this.bl_tree);
/*  540 */             count--;
/*      */           }
/*  542 */           send_code(16, this.bl_tree);
/*  543 */           send_bits(count - 3, 2);
/*  544 */         } else if (count <= 10) {
/*  545 */           send_code(17, this.bl_tree);
/*  546 */           send_bits(count - 3, 3);
/*      */         } else {
/*  548 */           send_code(18, this.bl_tree);
/*  549 */           send_bits(count - 11, 7);
/*      */         }
/*  551 */         count = 0;
/*  552 */         prevlen = curlen;
/*  553 */         if (nextlen == 0) {
/*  554 */           max_count = 138;
/*  555 */           min_count = 3;
/*  556 */         } else if (curlen == nextlen) {
/*  557 */           max_count = 6;
/*  558 */           min_count = 3;
/*      */         } else {
/*  560 */           max_count = 7;
/*  561 */           min_count = 4;
/*      */         }
/*      */       }
/*      */     }
/*      */   }
/*      */   
/*      */   final void put_byte(byte[] p, int start, int len)
/*      */   {
/*  569 */     System.arraycopy(p, start, this.pending_buf, this.pending, len);
/*  570 */     this.pending += len;
/*      */   }
/*      */   
/*      */   final void put_byte(byte c) {
/*  574 */     this.pending_buf[(this.pending++)] = c;
/*      */   }
/*      */   
/*      */   final void put_short(int w) {
/*  578 */     put_byte((byte)w);
/*  579 */     put_byte((byte)(w >>> 8));
/*      */   }
/*      */   
/*      */   final void putShortMSB(int b) {
/*  583 */     put_byte((byte)(b >> 8));
/*  584 */     put_byte((byte)b);
/*      */   }
/*      */   
/*      */   final void send_code(int c, short[] tree) {
/*  588 */     int c2 = c * 2;
/*  589 */     send_bits(tree[c2] & 0xFFFF, tree[(c2 + 1)] & 0xFFFF);
/*      */   }
/*      */   
/*      */   void send_bits(int value, int length) {
/*  593 */     int len = length;
/*  594 */     if (this.bi_valid > 16 - len) {
/*  595 */       int val = value;
/*      */       
/*  597 */       this.bi_buf = ((short)(this.bi_buf | val << this.bi_valid & 0xFFFF));
/*  598 */       put_short(this.bi_buf);
/*  599 */       this.bi_buf = ((short)(val >>> 16 - this.bi_valid));
/*  600 */       this.bi_valid += len - 16;
/*      */     }
/*      */     else {
/*  603 */       this.bi_buf = ((short)(this.bi_buf | value << this.bi_valid & 0xFFFF));
/*  604 */       this.bi_valid += len;
/*      */     }
/*      */   }
/*      */   
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */   void _tr_align()
/*      */   {
/*  618 */     send_bits(2, 3);
/*  619 */     send_code(256, StaticTree.static_ltree);
/*      */     
/*  621 */     bi_flush();
/*      */     
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*  627 */     if (1 + this.last_eob_len + 10 - this.bi_valid < 9) {
/*  628 */       send_bits(2, 3);
/*  629 */       send_code(256, StaticTree.static_ltree);
/*  630 */       bi_flush();
/*      */     }
/*  632 */     this.last_eob_len = 7;
/*      */   }
/*      */   
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */   boolean _tr_tally(int dist, int lc)
/*      */   {
/*  641 */     this.pending_buf[(this.d_buf + this.last_lit * 2)] = ((byte)(dist >>> 8));
/*  642 */     this.pending_buf[(this.d_buf + this.last_lit * 2 + 1)] = ((byte)dist);
/*      */     
/*  644 */     this.pending_buf[(this.l_buf + this.last_lit)] = ((byte)lc);
/*  645 */     this.last_lit += 1;
/*      */     
/*  647 */     if (dist == 0)
/*      */     {
/*  649 */       int tmp78_77 = (lc * 2); short[] tmp78_72 = this.dyn_ltree;tmp78_72[tmp78_77] = ((short)(tmp78_72[tmp78_77] + 1));
/*      */     } else {
/*  651 */       this.matches += 1;
/*      */       
/*  653 */       dist--; int 
/*  654 */         tmp117_116 = ((Tree._length_code[lc] + 256 + 1) * 2); short[] tmp117_101 = this.dyn_ltree;tmp117_101[tmp117_116] = ((short)(tmp117_101[tmp117_116] + 1)); int 
/*  655 */         tmp133_132 = (Tree.d_code(dist) * 2); short[] tmp133_124 = this.dyn_dtree;tmp133_124[tmp133_132] = ((short)(tmp133_124[tmp133_132] + 1));
/*      */     }
/*      */     
/*  658 */     if (((this.last_lit & 0x1FFF) == 0) && (this.level > 2))
/*      */     {
/*  660 */       int out_length = this.last_lit * 8;
/*  661 */       int in_length = this.strstart - this.block_start;
/*      */       
/*  663 */       for (int dcode = 0; dcode < 30; dcode++)
/*      */       {
/*  665 */         out_length = (int)(out_length + this.dyn_dtree[(dcode * 2)] * (5L + Tree.extra_dbits[dcode]));
/*      */       }
/*  667 */       out_length >>>= 3;
/*  668 */       if ((this.matches < this.last_lit / 2) && (out_length < in_length / 2)) {
/*  669 */         return true;
/*      */       }
/*      */     }
/*  672 */     return this.last_lit == this.lit_bufsize - 1;
/*      */   }
/*      */   
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */   void compress_block(short[] ltree, short[] dtree)
/*      */   {
/*  682 */     int lx = 0;
/*      */     
/*      */ 
/*      */ 
/*  686 */     if (this.last_lit != 0) {
/*      */       do {
/*  688 */         int dist = this.pending_buf[(this.d_buf + lx * 2)] << 8 & 0xFF00 | 
/*  689 */           this.pending_buf[(this.d_buf + lx * 2 + 1)] & 0xFF;
/*  690 */         int lc = this.pending_buf[(this.l_buf + lx)] & 0xFF;
/*  691 */         lx++;
/*      */         
/*  693 */         if (dist == 0) {
/*  694 */           send_code(lc, ltree);
/*      */         }
/*      */         else {
/*  697 */           int code = Tree._length_code[lc];
/*      */           
/*  699 */           send_code(code + 256 + 1, ltree);
/*      */           
/*  701 */           int extra = Tree.extra_lbits[code];
/*  702 */           if (extra != 0) {
/*  703 */             lc -= Tree.base_length[code];
/*  704 */             send_bits(lc, extra);
/*      */           }
/*  706 */           dist--;
/*  707 */           code = Tree.d_code(dist);
/*      */           
/*  709 */           send_code(code, dtree);
/*  710 */           extra = Tree.extra_dbits[code];
/*  711 */           if (extra != 0) {
/*  712 */             dist -= Tree.base_dist[code];
/*  713 */             send_bits(dist, extra);
/*      */           }
/*      */         }
/*  687 */       } while (
/*      */       
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*  719 */         lx < this.last_lit);
/*      */     }
/*      */     
/*  722 */     send_code(256, ltree);
/*  723 */     this.last_eob_len = ltree['ȁ'];
/*      */   }
/*      */   
/*      */ 
/*      */ 
/*      */ 
/*      */   void set_data_type()
/*      */   {
/*  731 */     int n = 0;
/*  732 */     int ascii_freq = 0;
/*  733 */     int bin_freq = 0;
/*  734 */     while (n < 7) {
/*  735 */       bin_freq += this.dyn_ltree[(n * 2)];
/*  736 */       n++;
/*      */     }
/*  738 */     while (n < 128) {
/*  739 */       ascii_freq += this.dyn_ltree[(n * 2)];
/*  740 */       n++;
/*      */     }
/*  742 */     while (n < 256) {
/*  743 */       bin_freq += this.dyn_ltree[(n * 2)];
/*  744 */       n++;
/*      */     }
/*  746 */     this.data_type = ((byte)(bin_freq > ascii_freq >>> 2 ? 0 : 1));
/*      */   }
/*      */   
/*      */   void bi_flush()
/*      */   {
/*  751 */     if (this.bi_valid == 16) {
/*  752 */       put_short(this.bi_buf);
/*  753 */       this.bi_buf = 0;
/*  754 */       this.bi_valid = 0;
/*  755 */     } else if (this.bi_valid >= 8) {
/*  756 */       put_byte((byte)this.bi_buf);
/*  757 */       this.bi_buf = ((short)(this.bi_buf >>> 8));
/*  758 */       this.bi_valid -= 8;
/*      */     }
/*      */   }
/*      */   
/*      */   void bi_windup()
/*      */   {
/*  764 */     if (this.bi_valid > 8) {
/*  765 */       put_short(this.bi_buf);
/*  766 */     } else if (this.bi_valid > 0) {
/*  767 */       put_byte((byte)this.bi_buf);
/*      */     }
/*  769 */     this.bi_buf = 0;
/*  770 */     this.bi_valid = 0;
/*      */   }
/*      */   
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */   void copy_block(int buf, int len, boolean header)
/*      */   {
/*  779 */     int index = 0;
/*  780 */     bi_windup();
/*  781 */     this.last_eob_len = 8;
/*      */     
/*  783 */     if (header) {
/*  784 */       put_short((short)len);
/*  785 */       put_short((short)(len ^ 0xFFFFFFFF));
/*      */     }
/*      */     
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*  792 */     put_byte(this.window, buf, len);
/*      */   }
/*      */   
/*      */   void flush_block_only(boolean eof) {
/*  796 */     _tr_flush_block(this.block_start >= 0 ? this.block_start : -1, this.strstart - 
/*  797 */       this.block_start, eof);
/*  798 */     this.block_start = this.strstart;
/*  799 */     this.strm.flush_pending();
/*      */   }
/*      */   
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */   int deflate_stored(int flush)
/*      */   {
/*  814 */     int max_block_size = 65535;
/*      */     
/*      */ 
/*  817 */     if (max_block_size > this.pending_buf_size - 5) {
/*  818 */       max_block_size = this.pending_buf_size - 5;
/*      */     }
/*      */     do
/*      */     {
/*      */       do
/*      */       {
/*  824 */         if (this.lookahead <= 1) {
/*  825 */           fill_window();
/*  826 */           if ((this.lookahead == 0) && (flush == 0))
/*  827 */             return 0;
/*  828 */           if (this.lookahead == 0) {
/*      */             break;
/*      */           }
/*      */         }
/*  832 */         this.strstart += this.lookahead;
/*  833 */         this.lookahead = 0;
/*      */         
/*      */ 
/*  836 */         int max_start = this.block_start + max_block_size;
/*  837 */         if ((this.strstart == 0) || (this.strstart >= max_start))
/*      */         {
/*  839 */           this.lookahead = (this.strstart - max_start);
/*  840 */           this.strstart = max_start;
/*      */           
/*  842 */           flush_block_only(false);
/*  843 */           if (this.strm.avail_out == 0) {
/*  844 */             return 0;
/*      */           }
/*      */           
/*      */         }
/*      */         
/*      */       }
/*  850 */       while (this.strstart - this.block_start < this.w_size - 262);
/*  851 */       flush_block_only(false);
/*  852 */     } while (this.strm.avail_out != 0);
/*  853 */     return 0;
/*      */     
/*      */ 
/*      */ 
/*  857 */     flush_block_only(flush == 4);
/*  858 */     if (this.strm.avail_out == 0) {
/*  859 */       return flush == 4 ? 2 : 0;
/*      */     }
/*  861 */     return flush == 4 ? 3 : 1;
/*      */   }
/*      */   
/*      */ 
/*      */ 
/*      */ 
/*      */   void _tr_stored_block(int buf, int stored_len, boolean eof)
/*      */   {
/*  869 */     send_bits(0 + (eof ? 1 : 0), 3);
/*  870 */     copy_block(buf, stored_len, true);
/*      */   }
/*      */   
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */   void _tr_flush_block(int buf, int stored_len, boolean eof)
/*      */   {
/*  880 */     int max_blindex = 0;
/*      */     int static_lenb;
/*      */     int opt_lenb;
/*  883 */     if (this.level > 0)
/*      */     {
/*  885 */       if (this.data_type == 2) {
/*  886 */         set_data_type();
/*      */       }
/*      */       
/*  889 */       this.l_desc.build_tree(this);
/*      */       
/*  891 */       this.d_desc.build_tree(this);
/*      */       
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*  900 */       max_blindex = build_bl_tree();
/*      */       
/*      */ 
/*      */ 
/*  904 */       int opt_lenb = this.opt_len + 3 + 7 >>> 3;
/*  905 */       int static_lenb = this.static_len + 3 + 7 >>> 3;
/*      */       
/*  907 */       if (static_lenb <= opt_lenb)
/*  908 */         opt_lenb = static_lenb;
/*      */     } else {
/*  910 */       opt_lenb = static_lenb = stored_len + 5;
/*      */     }
/*      */     
/*  913 */     if ((stored_len + 4 <= opt_lenb) && (buf != -1))
/*      */     {
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*  921 */       _tr_stored_block(buf, stored_len, eof);
/*  922 */     } else if (static_lenb == opt_lenb) {
/*  923 */       send_bits(2 + (eof ? 1 : 0), 3);
/*  924 */       compress_block(StaticTree.static_ltree, StaticTree.static_dtree);
/*      */     } else {
/*  926 */       send_bits(4 + (eof ? 1 : 0), 3);
/*  927 */       send_all_trees(this.l_desc.max_code + 1, this.d_desc.max_code + 1, 
/*  928 */         max_blindex + 1);
/*  929 */       compress_block(this.dyn_ltree, this.dyn_dtree);
/*      */     }
/*      */     
/*      */ 
/*      */ 
/*      */ 
/*  935 */     init_block();
/*      */     
/*  937 */     if (eof) {
/*  938 */       bi_windup();
/*      */     }
/*      */   }
/*      */   
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */   void fill_window()
/*      */   {
/*      */     do
/*      */     {
/*  956 */       int more = this.window_size - this.lookahead - this.strstart;
/*      */       
/*      */ 
/*  959 */       if ((more == 0) && (this.strstart == 0) && (this.lookahead == 0)) {
/*  960 */         more = this.w_size;
/*  961 */       } else if (more == -1)
/*      */       {
/*      */ 
/*      */ 
/*  965 */         more--;
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */       }
/*  971 */       else if (this.strstart >= this.w_size + this.w_size - 262) {
/*  972 */         System.arraycopy(this.window, this.w_size, this.window, 0, this.w_size);
/*  973 */         this.match_start -= this.w_size;
/*  974 */         this.strstart -= this.w_size;
/*  975 */         this.block_start -= this.w_size;
/*      */         
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*  985 */         int n = this.hash_size;
/*  986 */         int p = n;
/*      */         int m;
/*  988 */         do { m = this.head[(--p)] & 0xFFFF;
/*  989 */           this.head[p] = (m >= this.w_size ? (short)(m - this.w_size) : 0);
/*  990 */           n--; } while (n != 0);
/*      */         
/*  992 */         n = this.w_size;
/*  993 */         p = n;
/*      */         do {
/*  995 */           m = this.prev[(--p)] & 0xFFFF;
/*  996 */           this.prev[p] = (m >= this.w_size ? (short)(m - this.w_size) : 0);
/*      */           
/*      */ 
/*  999 */           n--; } while (n != 0);
/* 1000 */         more += this.w_size;
/*      */       }
/*      */       
/* 1003 */       if (this.strm.avail_in == 0) {
/* 1004 */         return;
/*      */       }
/*      */       
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/* 1017 */       int n = this.strm.read_buf(this.window, this.strstart + this.lookahead, more);
/* 1018 */       this.lookahead += n;
/*      */       
/*      */ 
/* 1021 */       if (this.lookahead >= 3) {
/* 1022 */         this.ins_h = (this.window[this.strstart] & 0xFF);
/* 1023 */         this.ins_h = 
/* 1024 */           ((this.ins_h << this.hash_shift ^ this.window[(this.strstart + 1)] & 0xFF) & this.hash_mask);
/*      */ 
/*      */       }
/*      */       
/*      */ 
/*      */     }
/* 1030 */     while ((this.lookahead < 262) && (this.strm.avail_in != 0));
/*      */   }
/*      */   
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */   int deflate_fast(int flush)
/*      */   {
/* 1040 */     int hash_head = 0;
/*      */     
/*      */     do
/*      */     {
/*      */       boolean bflush;
/*      */       
/*      */       do
/*      */       {
/* 1048 */         if (this.lookahead < 262) {
/* 1049 */           fill_window();
/* 1050 */           if ((this.lookahead < 262) && (flush == 0)) {
/* 1051 */             return 0;
/*      */           }
/* 1053 */           if (this.lookahead == 0) {
/*      */             break;
/*      */           }
/*      */         }
/*      */         
/*      */ 
/* 1059 */         if (this.lookahead >= 3) {
/* 1060 */           this.ins_h = 
/*      */           
/* 1062 */             ((this.ins_h << this.hash_shift ^ this.window[(this.strstart + 2)] & 0xFF) & this.hash_mask);
/*      */           
/*      */ 
/* 1065 */           hash_head = this.head[this.ins_h] & 0xFFFF;
/* 1066 */           this.prev[(this.strstart & this.w_mask)] = this.head[this.ins_h];
/* 1067 */           this.head[this.ins_h] = ((short)this.strstart);
/*      */         }
/*      */         
/*      */ 
/*      */ 
/*      */ 
/* 1073 */         if (hash_head != 0L)
/*      */         {
/* 1075 */           if ((this.strstart - hash_head & 0xFFFF) <= this.w_size - 262)
/*      */           {
/*      */ 
/*      */ 
/* 1079 */             if (this.strategy != 2) {
/* 1080 */               this.match_length = longest_match(hash_head);
/*      */             }
/*      */           }
/*      */         }
/* 1084 */         if (this.match_length >= 3)
/*      */         {
/*      */ 
/* 1087 */           boolean bflush = _tr_tally(this.strstart - this.match_start, this.match_length - 
/* 1088 */             3);
/*      */           
/* 1090 */           this.lookahead -= this.match_length;
/*      */           
/*      */ 
/*      */ 
/* 1094 */           if ((this.match_length <= this.max_lazy_match) && (this.lookahead >= 3)) {
/* 1095 */             this.match_length -= 1;
/*      */             do {
/* 1097 */               this.strstart += 1;
/*      */               
/* 1099 */               this.ins_h = 
/*      */               
/* 1101 */                 ((this.ins_h << this.hash_shift ^ this.window[(this.strstart + 2)] & 0xFF) & this.hash_mask);
/*      */               
/* 1103 */               hash_head = this.head[this.ins_h] & 0xFFFF;
/* 1104 */               this.prev[(this.strstart & this.w_mask)] = this.head[this.ins_h];
/* 1105 */               this.head[this.ins_h] = ((short)this.strstart);
/*      */ 
/*      */ 
/*      */             }
/* 1109 */             while (--this.match_length != 0);
/* 1110 */             this.strstart += 1;
/*      */           } else {
/* 1112 */             this.strstart += this.match_length;
/* 1113 */             this.match_length = 0;
/* 1114 */             this.ins_h = (this.window[this.strstart] & 0xFF);
/*      */             
/* 1116 */             this.ins_h = 
/* 1117 */               ((this.ins_h << this.hash_shift ^ this.window[(this.strstart + 1)] & 0xFF) & this.hash_mask);
/*      */           }
/*      */           
/*      */ 
/*      */         }
/*      */         else
/*      */         {
/*      */ 
/* 1125 */           bflush = _tr_tally(0, this.window[this.strstart] & 0xFF);
/* 1126 */           this.lookahead -= 1;
/* 1127 */           this.strstart += 1;
/*      */         }
/* 1129 */       } while (!bflush);
/*      */       
/* 1131 */       flush_block_only(false);
/* 1132 */     } while (this.strm.avail_out != 0);
/* 1133 */     return 0;
/*      */     
/*      */ 
/*      */ 
/* 1137 */     flush_block_only(flush == 4);
/* 1138 */     if (this.strm.avail_out == 0) {
/* 1139 */       if (flush == 4) {
/* 1140 */         return 2;
/*      */       }
/* 1142 */       return 0;
/*      */     }
/* 1144 */     return flush == 4 ? 3 : 1;
/*      */   }
/*      */   
/*      */ 
/*      */ 
/*      */ 
/*      */   int deflate_slow(int flush)
/*      */   {
/* 1152 */     int hash_head = 0;
/*      */     
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */     for (;;)
/*      */     {
/* 1162 */       if (this.lookahead < 262) {
/* 1163 */         fill_window();
/* 1164 */         if ((this.lookahead < 262) && (flush == 0)) {
/* 1165 */           return 0;
/*      */         }
/* 1167 */         if (this.lookahead == 0) {
/*      */           break;
/*      */         }
/*      */       }
/*      */       
/*      */ 
/*      */ 
/* 1174 */       if (this.lookahead >= 3) {
/* 1175 */         this.ins_h = 
/*      */         
/* 1177 */           ((this.ins_h << this.hash_shift ^ this.window[(this.strstart + 2)] & 0xFF) & this.hash_mask);
/*      */         
/* 1179 */         hash_head = this.head[this.ins_h] & 0xFFFF;
/* 1180 */         this.prev[(this.strstart & this.w_mask)] = this.head[this.ins_h];
/* 1181 */         this.head[this.ins_h] = ((short)this.strstart);
/*      */       }
/*      */       
/*      */ 
/* 1185 */       this.prev_length = this.match_length;
/* 1186 */       this.prev_match = this.match_start;
/* 1187 */       this.match_length = 2;
/*      */       
/* 1189 */       if ((hash_head != 0) && 
/* 1190 */         (this.prev_length < this.max_lazy_match))
/*      */       {
/* 1192 */         if ((this.strstart - hash_head & 0xFFFF) <= this.w_size - 262)
/*      */         {
/*      */ 
/*      */ 
/*      */ 
/* 1197 */           if (this.strategy != 2) {
/* 1198 */             this.match_length = longest_match(hash_head);
/*      */           }
/*      */           
/*      */ 
/* 1202 */           if ((this.match_length <= 5) && (
/* 1203 */             (this.strategy == 1) || ((this.match_length == 3) && 
/* 1204 */             (this.strstart - this.match_start > 4096))))
/*      */           {
/*      */ 
/*      */ 
/* 1208 */             this.match_length = 2;
/*      */           }
/*      */         }
/*      */       }
/*      */       
/*      */ 
/* 1214 */       if ((this.prev_length >= 3) && (this.match_length <= this.prev_length)) {
/* 1215 */         int max_insert = this.strstart + this.lookahead - 3;
/*      */         
/*      */ 
/*      */ 
/*      */ 
/* 1220 */         boolean bflush = _tr_tally(this.strstart - 1 - this.prev_match, this.prev_length - 
/* 1221 */           3);
/*      */         
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/* 1227 */         this.lookahead -= this.prev_length - 1;
/* 1228 */         this.prev_length -= 2;
/*      */         do {
/* 1230 */           if (++this.strstart <= max_insert) {
/* 1231 */             this.ins_h = 
/*      */             
/* 1233 */               ((this.ins_h << this.hash_shift ^ this.window[(this.strstart + 2)] & 0xFF) & this.hash_mask);
/*      */             
/* 1235 */             hash_head = this.head[this.ins_h] & 0xFFFF;
/* 1236 */             this.prev[(this.strstart & this.w_mask)] = this.head[this.ins_h];
/* 1237 */             this.head[this.ins_h] = ((short)this.strstart);
/*      */           }
/* 1239 */         } while (--this.prev_length != 0);
/* 1240 */         this.match_available = 0;
/* 1241 */         this.match_length = 2;
/* 1242 */         this.strstart += 1;
/*      */         
/* 1244 */         if (bflush) {
/* 1245 */           flush_block_only(false);
/* 1246 */           if (this.strm.avail_out == 0)
/* 1247 */             return 0;
/*      */         }
/* 1249 */       } else if (this.match_available != 0)
/*      */       {
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/* 1255 */         boolean bflush = _tr_tally(0, this.window[(this.strstart - 1)] & 0xFF);
/*      */         
/* 1257 */         if (bflush) {
/* 1258 */           flush_block_only(false);
/*      */         }
/* 1260 */         this.strstart += 1;
/* 1261 */         this.lookahead -= 1;
/* 1262 */         if (this.strm.avail_out == 0) {
/* 1263 */           return 0;
/*      */         }
/*      */       }
/*      */       else
/*      */       {
/* 1268 */         this.match_available = 1;
/* 1269 */         this.strstart += 1;
/* 1270 */         this.lookahead -= 1;
/*      */       }
/*      */     }
/*      */     
/* 1274 */     if (this.match_available != 0) {
/* 1275 */       boolean bflush = _tr_tally(0, this.window[(this.strstart - 1)] & 0xFF);
/* 1276 */       this.match_available = 0;
/*      */     }
/* 1278 */     flush_block_only(flush == 4);
/*      */     
/* 1280 */     if (this.strm.avail_out == 0) {
/* 1281 */       if (flush == 4) {
/* 1282 */         return 2;
/*      */       }
/* 1284 */       return 0;
/*      */     }
/*      */     
/* 1287 */     return flush == 4 ? 3 : 1;
/*      */   }
/*      */   
/*      */   int longest_match(int cur_match) {
/* 1291 */     int chain_length = this.max_chain_length;
/* 1292 */     int scan = this.strstart;
/*      */     
/*      */ 
/* 1295 */     int best_len = this.prev_length;
/* 1296 */     int limit = this.strstart > this.w_size - 262 ? this.strstart - (
/* 1297 */       this.w_size - 262) : 0;
/* 1298 */     int nice_match = this.nice_match;
/*      */     
/*      */ 
/*      */ 
/*      */ 
/* 1303 */     int wmask = this.w_mask;
/*      */     
/* 1305 */     int strend = this.strstart + 258;
/* 1306 */     byte scan_end1 = this.window[(scan + best_len - 1)];
/* 1307 */     byte scan_end = this.window[(scan + best_len)];
/*      */     
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/* 1314 */     if (this.prev_length >= this.good_match) {
/* 1315 */       chain_length >>= 2;
/*      */     }
/*      */     
/*      */ 
/*      */ 
/*      */ 
/* 1321 */     if (nice_match > this.lookahead) {
/* 1322 */       nice_match = this.lookahead;
/*      */     }
/*      */     do {
/* 1325 */       int match = cur_match;
/*      */       
/*      */ 
/*      */ 
/* 1329 */       if ((this.window[(match + best_len)] == scan_end) && 
/* 1330 */         (this.window[(match + best_len - 1)] == scan_end1) && 
/* 1331 */         (this.window[match] == this.window[scan]) && 
/* 1332 */         (this.window[(++match)] == this.window[(scan + 1)]))
/*      */       {
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/* 1340 */         scan += 2;
/* 1341 */         match++;
/*      */         
/*      */ 
/*      */ 
/*      */ 
/* 1346 */         while ((this.window[(++scan)] == this.window[(++match)]) && 
/* 1347 */           (this.window[(++scan)] == this.window[(++match)]) && 
/* 1348 */           (this.window[(++scan)] == this.window[(++match)]) && 
/* 1349 */           (this.window[(++scan)] == this.window[(++match)]) && 
/* 1350 */           (this.window[(++scan)] == this.window[(++match)]) && 
/* 1351 */           (this.window[(++scan)] == this.window[(++match)]) && 
/* 1352 */           (this.window[(++scan)] == this.window[(++match)]) && 
/* 1353 */           (this.window[(++scan)] == this.window[(++match)]) && (scan < strend)) {}
/*      */         
/* 1355 */         int len = 258 - (strend - scan);
/* 1356 */         scan = strend - 258;
/*      */         
/* 1358 */         if (len > best_len) {
/* 1359 */           this.match_start = cur_match;
/* 1360 */           best_len = len;
/* 1361 */           if (len >= nice_match)
/*      */             break;
/* 1363 */           scan_end1 = this.window[(scan + best_len - 1)];
/* 1364 */           scan_end = this.window[(scan + best_len)];
/*      */         }
/*      */       }
/* 1367 */       if ((cur_match = this.prev[(cur_match & wmask)] & 0xFFFF) <= limit) break;
/* 1368 */       chain_length--; } while (chain_length != 0);
/*      */     
/* 1370 */     if (best_len <= this.lookahead)
/* 1371 */       return best_len;
/* 1372 */     return this.lookahead;
/*      */   }
/*      */   
/*      */   int deflateInit(ZStream strm, int level, int bits) {
/* 1376 */     return deflateInit2(strm, level, 8, bits, 8, 
/* 1377 */       0);
/*      */   }
/*      */   
/*      */   int deflateInit(ZStream strm, int level) {
/* 1381 */     return deflateInit(strm, level, 15);
/*      */   }
/*      */   
/*      */   int deflateInit2(ZStream strm, int level, int method, int windowBits, int memLevel, int strategy)
/*      */   {
/* 1386 */     int noheader = 0;
/*      */     
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/* 1395 */     strm.msg = null;
/*      */     
/* 1397 */     if (level == -1) {
/* 1398 */       level = 6;
/*      */     }
/* 1400 */     if (windowBits < 0) {
/* 1401 */       noheader = 1;
/* 1402 */       windowBits = -windowBits;
/*      */     }
/*      */     
/* 1405 */     if ((memLevel < 1) || (memLevel > 9) || (method != 8) || 
/* 1406 */       (windowBits < 9) || (windowBits > 15) || (level < 0) || (level > 9) || 
/* 1407 */       (strategy < 0) || (strategy > 2)) {
/* 1408 */       return -2;
/*      */     }
/*      */     
/* 1411 */     strm.dstate = this;
/*      */     
/* 1413 */     this.noheader = noheader;
/* 1414 */     this.w_bits = windowBits;
/* 1415 */     this.w_size = (1 << this.w_bits);
/* 1416 */     this.w_mask = (this.w_size - 1);
/*      */     
/* 1418 */     this.hash_bits = (memLevel + 7);
/* 1419 */     this.hash_size = (1 << this.hash_bits);
/* 1420 */     this.hash_mask = (this.hash_size - 1);
/* 1421 */     this.hash_shift = ((this.hash_bits + 3 - 1) / 3);
/*      */     
/* 1423 */     this.window = new byte[this.w_size * 2];
/* 1424 */     this.prev = new short[this.w_size];
/* 1425 */     this.head = new short[this.hash_size];
/*      */     
/* 1427 */     this.lit_bufsize = (1 << memLevel + 6);
/*      */     
/*      */ 
/*      */ 
/* 1431 */     this.pending_buf = new byte[this.lit_bufsize * 4];
/* 1432 */     this.pending_buf_size = (this.lit_bufsize * 4);
/*      */     
/* 1434 */     this.d_buf = (this.lit_bufsize / 2);
/* 1435 */     this.l_buf = (3 * this.lit_bufsize);
/*      */     
/* 1437 */     this.level = level;
/*      */     
/*      */ 
/*      */ 
/* 1441 */     this.strategy = strategy;
/* 1442 */     this.method = ((byte)method);
/*      */     
/* 1444 */     return deflateReset(strm);
/*      */   }
/*      */   
/*      */   int deflateReset(ZStream strm) {
/* 1448 */     strm.total_in = (strm.total_out = 0L);
/* 1449 */     strm.msg = null;
/* 1450 */     strm.data_type = 2;
/*      */     
/* 1452 */     this.pending = 0;
/* 1453 */     this.pending_out = 0;
/*      */     
/* 1455 */     if (this.noheader < 0) {
/* 1456 */       this.noheader = 0;
/*      */     }
/* 1458 */     this.status = (this.noheader != 0 ? 113 : 42);
/* 1459 */     strm.adler = strm._adler.adler32(0L, null, 0, 0);
/*      */     
/* 1461 */     this.last_flush = 0;
/*      */     
/* 1463 */     tr_init();
/* 1464 */     lm_init();
/* 1465 */     return 0;
/*      */   }
/*      */   
/*      */   int deflateEnd() {
/* 1469 */     if ((this.status != 42) && (this.status != 113) && 
/* 1470 */       (this.status != 666)) {
/* 1471 */       return -2;
/*      */     }
/*      */     
/* 1474 */     this.pending_buf = null;
/* 1475 */     this.head = null;
/* 1476 */     this.prev = null;
/* 1477 */     this.window = null;
/*      */     
/*      */ 
/* 1480 */     return this.status == 113 ? -3 : 0;
/*      */   }
/*      */   
/*      */   int deflateParams(ZStream strm, int _level, int _strategy) {
/* 1484 */     int err = 0;
/*      */     
/* 1486 */     if (_level == -1) {
/* 1487 */       _level = 6;
/*      */     }
/* 1489 */     if ((_level < 0) || (_level > 9) || (_strategy < 0) || 
/* 1490 */       (_strategy > 2)) {
/* 1491 */       return -2;
/*      */     }
/*      */     
/* 1494 */     if ((config_table[this.level].func != config_table[_level].func) && 
/* 1495 */       (strm.total_in != 0L))
/*      */     {
/* 1497 */       err = strm.deflate(1);
/*      */     }
/*      */     
/* 1500 */     if (this.level != _level) {
/* 1501 */       this.level = _level;
/* 1502 */       this.max_lazy_match = config_table[this.level].max_lazy;
/* 1503 */       this.good_match = config_table[this.level].good_length;
/* 1504 */       this.nice_match = config_table[this.level].nice_length;
/* 1505 */       this.max_chain_length = config_table[this.level].max_chain;
/*      */     }
/* 1507 */     this.strategy = _strategy;
/* 1508 */     return err;
/*      */   }
/*      */   
/*      */   int deflateSetDictionary(ZStream strm, byte[] dictionary, int dictLength) {
/* 1512 */     int length = dictLength;
/* 1513 */     int index = 0;
/*      */     
/* 1515 */     if ((dictionary == null) || (this.status != 42)) {
/* 1516 */       return -2;
/*      */     }
/* 1518 */     strm.adler = strm._adler.adler32(strm.adler, dictionary, 0, dictLength);
/*      */     
/* 1520 */     if (length < 3)
/* 1521 */       return 0;
/* 1522 */     if (length > this.w_size - 262) {
/* 1523 */       length = this.w_size - 262;
/* 1524 */       index = dictLength - length;
/*      */     }
/* 1526 */     System.arraycopy(dictionary, index, this.window, 0, length);
/* 1527 */     this.strstart = length;
/* 1528 */     this.block_start = length;
/*      */     
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/* 1534 */     this.ins_h = (this.window[0] & 0xFF);
/* 1535 */     this.ins_h = ((this.ins_h << this.hash_shift ^ this.window[1] & 0xFF) & this.hash_mask);
/*      */     
/* 1537 */     for (int n = 0; n <= length - 3; n++) {
/* 1538 */       this.ins_h = 
/* 1539 */         ((this.ins_h << this.hash_shift ^ this.window[(n + 2)] & 0xFF) & this.hash_mask);
/* 1540 */       this.prev[(n & this.w_mask)] = this.head[this.ins_h];
/* 1541 */       this.head[this.ins_h] = ((short)n);
/*      */     }
/* 1543 */     return 0;
/*      */   }
/*      */   
/*      */ 
/*      */   int deflate(ZStream strm, int flush)
/*      */   {
/* 1549 */     if ((flush > 4) || (flush < 0)) {
/* 1550 */       return -2;
/*      */     }
/*      */     
/* 1553 */     if ((strm.next_out == null) || 
/* 1554 */       ((strm.next_in == null) && (strm.avail_in != 0)) || (
/* 1555 */       (this.status == 666) && (flush != 4))) {
/* 1556 */       strm.msg = z_errmsg[4];
/* 1557 */       return -2;
/*      */     }
/* 1559 */     if (strm.avail_out == 0) {
/* 1560 */       strm.msg = z_errmsg[7];
/* 1561 */       return -5;
/*      */     }
/*      */     
/* 1564 */     this.strm = strm;
/* 1565 */     int old_flush = this.last_flush;
/* 1566 */     this.last_flush = flush;
/*      */     
/*      */ 
/* 1569 */     if (this.status == 42) {
/* 1570 */       int header = 8 + (this.w_bits - 8 << 4) << 8;
/* 1571 */       int level_flags = (this.level - 1 & 0xFF) >> 1;
/*      */       
/* 1573 */       if (level_flags > 3)
/* 1574 */         level_flags = 3;
/* 1575 */       header |= level_flags << 6;
/* 1576 */       if (this.strstart != 0)
/* 1577 */         header |= 0x20;
/* 1578 */       header += 31 - header % 31;
/*      */       
/* 1580 */       this.status = 113;
/* 1581 */       putShortMSB(header);
/*      */       
/*      */ 
/* 1584 */       if (this.strstart != 0) {
/* 1585 */         putShortMSB((int)(strm.adler >>> 16));
/* 1586 */         putShortMSB((int)(strm.adler & 0xFFFF));
/*      */       }
/* 1588 */       strm.adler = strm._adler.adler32(0L, null, 0, 0);
/*      */     }
/*      */     
/*      */ 
/* 1592 */     if (this.pending != 0) {
/* 1593 */       strm.flush_pending();
/* 1594 */       if (strm.avail_out == 0)
/*      */       {
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/* 1601 */         this.last_flush = -1;
/* 1602 */         return 0;
/*      */ 
/*      */       }
/*      */       
/*      */ 
/*      */ 
/*      */     }
/* 1609 */     else if ((strm.avail_in == 0) && (flush <= old_flush) && 
/* 1610 */       (flush != 4)) {
/* 1611 */       strm.msg = z_errmsg[7];
/* 1612 */       return -5;
/*      */     }
/*      */     
/*      */ 
/* 1616 */     if ((this.status == 666) && (strm.avail_in != 0)) {
/* 1617 */       strm.msg = z_errmsg[7];
/* 1618 */       return -5;
/*      */     }
/*      */     
/*      */ 
/* 1622 */     if ((strm.avail_in != 0) || (this.lookahead != 0) || (
/* 1623 */       (flush != 0) && (this.status != 666))) {
/* 1624 */       int bstate = -1;
/* 1625 */       switch (config_table[this.level].func) {
/*      */       case 0: 
/* 1627 */         bstate = deflate_stored(flush);
/* 1628 */         break;
/*      */       case 1: 
/* 1630 */         bstate = deflate_fast(flush);
/* 1631 */         break;
/*      */       case 2: 
/* 1633 */         bstate = deflate_slow(flush);
/*      */       }
/*      */       
/*      */       
/*      */ 
/* 1638 */       if ((bstate == 2) || (bstate == 3)) {
/* 1639 */         this.status = 666;
/*      */       }
/* 1641 */       if ((bstate == 0) || (bstate == 2)) {
/* 1642 */         if (strm.avail_out == 0) {
/* 1643 */           this.last_flush = -1;
/*      */         }
/* 1645 */         return 0;
/*      */       }
/*      */       
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/* 1654 */       if (bstate == 1) {
/* 1655 */         if (flush == 1) {
/* 1656 */           _tr_align();
/*      */         } else {
/* 1658 */           _tr_stored_block(0, 0, false);
/*      */           
/*      */ 
/* 1661 */           if (flush == 3)
/*      */           {
/* 1663 */             for (int i = 0; i < this.hash_size; i++)
/*      */             {
/* 1665 */               this.head[i] = 0; }
/*      */           }
/*      */         }
/* 1668 */         strm.flush_pending();
/* 1669 */         if (strm.avail_out == 0) {
/* 1670 */           this.last_flush = -1;
/* 1671 */           return 0;
/*      */         }
/*      */       }
/*      */     }
/*      */     
/* 1676 */     if (flush != 4)
/* 1677 */       return 0;
/* 1678 */     if (this.noheader != 0) {
/* 1679 */       return 1;
/*      */     }
/*      */     
/* 1682 */     putShortMSB((int)(strm.adler >>> 16));
/* 1683 */     putShortMSB((int)(strm.adler & 0xFFFF));
/* 1684 */     strm.flush_pending();
/*      */     
/*      */ 
/*      */ 
/* 1688 */     this.noheader = -1;
/* 1689 */     return this.pending != 0 ? 0 : 1;
/*      */   }
/*      */ }


/* Location:              D:\Program Files\DBMS_20150813\jdbc\Dm7JdbcDriver17.jar!\com\jcraft\jzlib\Deflate.class
 * Java compiler version: 2 (46.0)
 * JD-Core Version:       0.7.1
 */